<!DOCTYPE html>
<html>
<head>
    

    

    



    <meta charset="utf-8">
    
    
    
    
    <title>MySQL数据库 | SongKaBaKa</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="">
    <meta name="description" content="数据库入门第二章 数据库和表的基本操作数据库基础知识创建数据库CREATE DATABASE [IF NOE EXISTS] db_name; CREATE DATABASE mydb1; create database mydb2 character set gbk; create database mydb3 character set utf8 collate utf8_bin; 查看数据库">
<meta property="og:type" content="article">
<meta property="og:title" content="MySQL数据库">
<meta property="og:url" content="https://gitee.com/songbug/blog.git/2020/12/18/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/index.html">
<meta property="og:site_name" content="SongKaBaKa">
<meta property="og:description" content="数据库入门第二章 数据库和表的基本操作数据库基础知识创建数据库CREATE DATABASE [IF NOE EXISTS] db_name; CREATE DATABASE mydb1; create database mydb2 character set gbk; create database mydb3 character set utf8 collate utf8_bin; 查看数据库">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2020-12-18T12:15:18.762Z">
<meta property="article:modified_time" content="2021-01-13T08:23:28.193Z">
<meta property="article:author" content="Song Wani">
<meta name="twitter:card" content="summary">
    
    <link rel="shortcut icon" href="/blog/favicon.ico">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

<meta name="generator" content="Hexo 4.2.1"></head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/blog/img/brand.jpg)">
      <div class="brand">
        <a href="/blog/" class="avatar waves-effect waves-circle waves-light">
          <img src="/blog/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">Song Wani</h5>
          <a href="mailto:bugsong@wo.cn" title="bugsong@wo.cn" class="mail">bugsong@wo.cn</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/blog/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/blog/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                Archives
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/blog/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                Tags
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/blog/categories"  >
                <i class="icon icon-lg icon-th-list"></i>
                Categories
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://songbug.gitee.io/blog" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">MySQL数据库</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="Search">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">MySQL数据库</h1>
        <h5 class="subtitle">
            
                <time datetime="2020-12-18T12:15:18.762Z" itemprop="datePublished" class="page-time">
  2020-12-18
</time>


            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap post-toc-shrink" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#数据库入门"><span class="post-toc-number">1.</span> <span class="post-toc-text">数据库入门</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#第二章-数据库和表的基本操作"><span class="post-toc-number">1.1.</span> <span class="post-toc-text">第二章 数据库和表的基本操作</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#数据库基础知识"><span class="post-toc-number">1.1.1.</span> <span class="post-toc-text">数据库基础知识</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#创建数据库"><span class="post-toc-number">1.1.1.1.</span> <span class="post-toc-text">创建数据库</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#查看数据库"><span class="post-toc-number">1.1.1.2.</span> <span class="post-toc-text">查看数据库</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#修改数据库"><span class="post-toc-number">1.1.1.3.</span> <span class="post-toc-text">修改数据库</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#选择数据库"><span class="post-toc-number">1.1.1.4.</span> <span class="post-toc-text">选择数据库</span></a></li></ol></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#数据类型"><span class="post-toc-number">1.1.2.</span> <span class="post-toc-text">数据类型</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#整型"><span class="post-toc-number">1.1.2.1.</span> <span class="post-toc-text">整型</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#浮点数、定点数"><span class="post-toc-number">1.1.2.2.</span> <span class="post-toc-text">浮点数、定点数</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#日期与时间"><span class="post-toc-number">1.1.2.3.</span> <span class="post-toc-text">日期与时间</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#字符串"><span class="post-toc-number">1.1.2.4.</span> <span class="post-toc-text">字符串</span></a></li></ol></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#表的操作"><span class="post-toc-number">1.1.3.</span> <span class="post-toc-text">表的操作</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#增加表"><span class="post-toc-number">1.1.3.1.</span> <span class="post-toc-text">增加表</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#查看表"><span class="post-toc-number">1.1.3.2.</span> <span class="post-toc-text">查看表</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#修改表"><span class="post-toc-number">1.1.3.3.</span> <span class="post-toc-text">修改表</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#删除表"><span class="post-toc-number">1.1.3.4.</span> <span class="post-toc-text">删除表</span></a></li></ol></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#表的约束"><span class="post-toc-number">1.1.4.</span> <span class="post-toc-text">表的约束</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#主键约束"><span class="post-toc-number">1.1.4.1.</span> <span class="post-toc-text">主键约束</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#非空约束"><span class="post-toc-number">1.1.4.2.</span> <span class="post-toc-text">非空约束</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#唯一约束"><span class="post-toc-number">1.1.4.3.</span> <span class="post-toc-text">唯一约束</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#默认约束"><span class="post-toc-number">1.1.4.4.</span> <span class="post-toc-text">默认约束</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#自增字段"><span class="post-toc-number">1.1.4.5.</span> <span class="post-toc-text">自增字段</span></a></li></ol></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#索引"><span class="post-toc-number">1.1.5.</span> <span class="post-toc-text">索引</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#概念"><span class="post-toc-number">1.1.5.1.</span> <span class="post-toc-text">概念</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-6"><a class="post-toc-link" href="#普通索引"><span class="post-toc-number">1.1.5.1.0.1.</span> <span class="post-toc-text">普通索引</span></a></li><li class="post-toc-item post-toc-level-6"><a class="post-toc-link" href="#唯一索引"><span class="post-toc-number">1.1.5.1.0.2.</span> <span class="post-toc-text">唯一索引</span></a></li><li class="post-toc-item post-toc-level-6"><a class="post-toc-link" href="#全文索引"><span class="post-toc-number">1.1.5.1.0.3.</span> <span class="post-toc-text">全文索引</span></a></li><li class="post-toc-item post-toc-level-6"><a class="post-toc-link" href="#单列索引"><span class="post-toc-number">1.1.5.1.0.4.</span> <span class="post-toc-text">单列索引</span></a></li><li class="post-toc-item post-toc-level-6"><a class="post-toc-link" href="#多列索引"><span class="post-toc-number">1.1.5.1.0.5.</span> <span class="post-toc-text">多列索引</span></a></li></ol></li></ol></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#创建索引"><span class="post-toc-number">1.1.5.2.</span> <span class="post-toc-text">创建索引</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#创建表时创建索引"><span class="post-toc-number">1.1.5.2.1.</span> <span class="post-toc-text">创建表时创建索引</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#使用CREATE语句创建索引"><span class="post-toc-number">1.1.5.2.2.</span> <span class="post-toc-text">使用CREATE语句创建索引</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#使用ALTER-TABLE语句创建索引"><span class="post-toc-number">1.1.5.2.3.</span> <span class="post-toc-text">使用ALTER TABLE语句创建索引</span></a></li></ol></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#删除索引"><span class="post-toc-number">1.1.5.3.</span> <span class="post-toc-text">删除索引</span></a></li></ol></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#第三章-添加、更新与删除数据"><span class="post-toc-number">1.2.</span> <span class="post-toc-text">第三章 添加、更新与删除数据</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#添加数据"><span class="post-toc-number">1.2.1.</span> <span class="post-toc-text">添加数据</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#更新数据"><span class="post-toc-number">1.2.2.</span> <span class="post-toc-text">更新数据</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#删除数据"><span class="post-toc-number">1.2.3.</span> <span class="post-toc-text">删除数据</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#第四章-表单查询"><span class="post-toc-number">1.3.</span> <span class="post-toc-text">第四章 表单查询</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#简单查询"><span class="post-toc-number">1.3.1.</span> <span class="post-toc-text">简单查询</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#全部查询"><span class="post-toc-number">1.3.1.1.</span> <span class="post-toc-text">全部查询</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#查询并运算后显示"><span class="post-toc-number">1.3.1.2.</span> <span class="post-toc-text">查询并运算后显示</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#指定别名"><span class="post-toc-number">1.3.1.3.</span> <span class="post-toc-text">指定别名</span></a></li></ol></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#条件查询"><span class="post-toc-number">1.3.2.</span> <span class="post-toc-text">条件查询</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#WHERE子句过滤查询"><span class="post-toc-number">1.3.2.1.</span> <span class="post-toc-text">WHERE子句过滤查询</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#聚合函数"><span class="post-toc-number">1.3.2.2.</span> <span class="post-toc-text">聚合函数</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#带有排序的查询"><span class="post-toc-number">1.3.2.3.</span> <span class="post-toc-text">带有排序的查询</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#分组查询"><span class="post-toc-number">1.3.2.4.</span> <span class="post-toc-text">分组查询</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#使用LIMIT限制查询结果的数量"><span class="post-toc-number">1.3.2.5.</span> <span class="post-toc-text">使用LIMIT限制查询结果的数量</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#常用函数"><span class="post-toc-number">1.3.2.6.</span> <span class="post-toc-text">常用函数</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#函了个数，方了个法。"><span class="post-toc-number">1.3.2.6.1.</span> <span class="post-toc-text">函了个数，方了个法。</span></a></li><li class="post-toc-item post-toc-level-5"><a class="post-toc-link" href="#数据类型-1"><span class="post-toc-number">1.3.2.6.2.</span> <span class="post-toc-text">数据类型</span></a></li></ol></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#别名"><span class="post-toc-number">1.3.2.7.</span> <span class="post-toc-text">别名</span></a></li></ol></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#第五章-多表操作"><span class="post-toc-number">1.4.</span> <span class="post-toc-text">第五章 多表操作</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#外键"><span class="post-toc-number">1.4.1.</span> <span class="post-toc-text">外键</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#为关联表添加数据"><span class="post-toc-number">1.4.2.</span> <span class="post-toc-text">为关联表添加数据</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#删除关联表数据"><span class="post-toc-number">1.4.3.</span> <span class="post-toc-text">删除关联表数据</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#交叉连接"><span class="post-toc-number">1.4.4.</span> <span class="post-toc-text">交叉连接</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#内连接查询"><span class="post-toc-number">1.4.4.1.</span> <span class="post-toc-text">内连接查询</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#左外链接查询"><span class="post-toc-number">1.4.4.2.</span> <span class="post-toc-text">左外链接查询</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#右外链接查询"><span class="post-toc-number">1.4.4.3.</span> <span class="post-toc-text">右外链接查询</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#全外链接查询"><span class="post-toc-number">1.4.4.4.</span> <span class="post-toc-text">全外链接查询</span></a></li></ol></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#带有IN关键字的子查询"><span class="post-toc-number">1.4.5.</span> <span class="post-toc-text">带有IN关键字的子查询</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#带有EXISTS关键字的查询"><span class="post-toc-number">1.4.6.</span> <span class="post-toc-text">带有EXISTS关键字的查询</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#带有ANY关键字的查询"><span class="post-toc-number">1.4.6.1.</span> <span class="post-toc-text">带有ANY关键字的查询</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#带有ALL关键字的查询"><span class="post-toc-number">1.4.6.2.</span> <span class="post-toc-text">带有ALL关键字的查询</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#带比较运算符的查询"><span class="post-toc-number">1.4.6.3.</span> <span class="post-toc-text">带比较运算符的查询</span></a></li></ol></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#第六章-事务和存储过程"><span class="post-toc-number">1.5.</span> <span class="post-toc-text">第六章 事务和存储过程</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#事务"><span class="post-toc-number">1.5.1.</span> <span class="post-toc-text">事务</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#事务的隔离级别"><span class="post-toc-number">1.5.2.</span> <span class="post-toc-text">事务的隔离级别</span></a></li></ol></li></ol></li></ol>
        </nav>
    </aside>


<article id="post-MySQL数据库"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">MySQL数据库</h1>
        <div class="post-meta">
            <time class="post-time" title="2020-12-18 20:15:18" datetime="2020-12-18T12:15:18.762Z"  itemprop="datePublished">2020-12-18</time>

            


            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h1 id="数据库入门"><a href="#数据库入门" class="headerlink" title="数据库入门"></a>数据库入门</h1><h2 id="第二章-数据库和表的基本操作"><a href="#第二章-数据库和表的基本操作" class="headerlink" title="第二章 数据库和表的基本操作"></a>第二章 数据库和表的基本操作</h2><h3 id="数据库基础知识"><a href="#数据库基础知识" class="headerlink" title="数据库基础知识"></a>数据库基础知识</h3><h4 id="创建数据库"><a href="#创建数据库" class="headerlink" title="创建数据库"></a>创建数据库</h4><p>CREATE DATABASE [IF NOE EXISTS] db_name;</p>
<p>CREATE DATABASE mydb1;</p>
<p>create database mydb2 character set gbk;</p>
<p>create database mydb3 character set utf8 collate utf8_bin;</p>
<h4 id="查看数据库"><a href="#查看数据库" class="headerlink" title="查看数据库"></a>查看数据库</h4><p><code>SHOW DATABASES</code>查看所有数据库</p>
<p><code>SHOW CREATE DATABASE mydb2</code>查看创建的数据库的定义信息</p>
<h4 id="修改数据库"><a href="#修改数据库" class="headerlink" title="修改数据库"></a>修改数据库</h4><p><code>ALTER DATABASE db_name [CHARACTER SET charset_name] [COLLATE collation_name]</code></p>
<h4 id="选择数据库"><a href="#选择数据库" class="headerlink" title="选择数据库"></a>选择数据库</h4><p>use db_name;</p>
<p><code>slect database()</code>查看当前所选的数据库</p>
<h3 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h3><h4 id="整型"><a href="#整型" class="headerlink" title="整型"></a>整型</h4><p>TINYINT 1</p>
<p>SMALLINT 2</p>
<p>MEDIUMINT 3</p>
<p>INT 4</p>
<p>BIGINT 8</p>
<h4 id="浮点数、定点数"><a href="#浮点数、定点数" class="headerlink" title="浮点数、定点数"></a>浮点数、定点数</h4><p><code>FLOAT 4</code></p>
<p><code>DOUBLE 8</code></p>
<p><code>DECIMAL(M,D) M+2</code>将M理解为总位数，将D理解为小数位数，且M&lt;D</p>
<h4 id="日期与时间"><a href="#日期与时间" class="headerlink" title="日期与时间"></a>日期与时间</h4><p>YEAR 1</p>
<p><code>DATE 4</code>横杠分割或省去，年月日，<code>CURRENT_DATE/NOW()</code>表示系统当前日期</p>
<p><code>DATE 8</code>显示形式一般为D HH:MM:SS,插入时的值为<code>D*24+HH:MM:SS</code>；也可以省略引号插入/读取，满24小时并不会满进，而是继续累加；CURRENT_TIME/NOW()</p>
<p><code>TIMESTAMP 4</code>时间戳</p>
<p>输入方法</p>
<ol>
<li><code>CURRENT_TIMESTAMP</code>来输入系统当前日期和时间</li>
<li><code>NULL</code>系统会输入系统当前日期和时间</li>
<li>无任何输入时，系统会输入系统当前日期和时间</li>
</ol>
<h4 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h4><ol>
<li><code>CHAR(M)</code>定度，省时间</li>
<li><code>VARCHAR(M)</code>变长，省空间</li>
<li><code>BINARY</code>二进制文件</li>
<li><code>VARBINARY</code>二进制文件</li>
<li><code>TEXT</code><ol>
<li>TINYTEXT</li>
<li>TEXT</li>
<li>MEDIUMTEXT</li>
<li>LONGTEXT</li>
</ol>
</li>
<li><code>BLOB</code>大二进制<ol>
<li>TINYBLOB</li>
<li>BLOB</li>
<li>MEDIUMBLOB</li>
<li>LONGBOLB</li>
</ol>
</li>
<li><code>ENUM(&#39;值1&#39;,&#39;值2&#39;,&#39;值3&#39;,...&#39;值n&#39;)</code>，拥有编号，从1开始</li>
<li><code>SET(&#39;值1&#39;,&#39;值2&#39;,&#39;值3&#39;,...&#39;值n&#39;)</code>，可0可多</li>
<li><code>BIT(M)</code>若值长小于M，左边补零，范围1-64，表示几位二进制</li>
</ol>
<h3 id="表的操作"><a href="#表的操作" class="headerlink" title="表的操作"></a>表的操作</h3><h4 id="增加表"><a href="#增加表" class="headerlink" title="增加表"></a>增加表</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">CREATE TABLE 表名(</span><br><span class="line">	field1 datetype,</span><br><span class="line">	field2 datetype,</span><br><span class="line">	field3 datetype,</span><br><span class="line">)character set 字符集 collate 校对规则</span><br></pre></td></tr></table></figure>

<p>尽量在一个库中使用相同的字符集和校对规则</p>
<p>例子：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">create table employee(</span><br><span class="line">	id int,</span><br><span class="line">	name varchar(20),</span><br><span class="line">	gender char(1),</span><br><span class="line">	birthday date,</span><br><span class="line">	entry_date date,</span><br><span class="line">	job varchar(50),</span><br><span class="line">	salay double,</span><br><span class="line">	resume text</span><br><span class="line">);</span><br></pre></td></tr></table></figure>

<h4 id="查看表"><a href="#查看表" class="headerlink" title="查看表"></a>查看表</h4><ol>
<li><code>DESC 表名</code>查看当前表结构</li>
<li><code>SHOW DATABASES</code>查看库中所有表</li>
<li><code>SHOW CREAT TABLE 表名</code>查看建表的语句</li>
</ol>
<h4 id="修改表"><a href="#修改表" class="headerlink" title="修改表"></a>修改表</h4><ol>
<li><p>增加列</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ALTER TABLE 表名</span><br><span class="line">ADD</span><br><span class="line">列名 数据类型</span><br></pre></td></tr></table></figure>
</li>
<li><p>修改列</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">ALTER TABLE 表名</span><br><span class="line">MODIFY</span><br><span class="line">列名 数据类型</span><br><span class="line">#单纯修改列的数据类型</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除列</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ALTER TABLE 表名</span><br><span class="line">DROP</span><br><span class="line">列名</span><br></pre></td></tr></table></figure>
</li>
<li><p>修改表名</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">REANAME TABLE 旧表名 to 新表名</span><br></pre></td></tr></table></figure>
</li>
<li><p>修改字符集</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ALTER TABLE 表名</span><br><span class="line">CHARACTER SET</span><br><span class="line">utf8</span><br></pre></td></tr></table></figure>
</li>
<li><p>修改列名</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ALTER TABLE 表名</span><br><span class="line">CHANGE</span><br><span class="line">旧列名 新列名 数据类型</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h4 id="删除表"><a href="#删除表" class="headerlink" title="删除表"></a>删除表</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">DROP TABLE 表名</span><br></pre></td></tr></table></figure>

<h3 id="表的约束"><a href="#表的约束" class="headerlink" title="表的约束"></a>表的约束</h3><ul>
<li>PRIMARY KEY</li>
<li>FOREIGN KEY</li>
<li>NOT NULL</li>
<li>UNIQUE</li>
<li>DEFAULT</li>
</ul>
<h4 id="主键约束"><a href="#主键约束" class="headerlink" title="主键约束"></a>主键约束</h4><ol>
<li><p>单字段主键</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">creat table employee(</span><br><span class="line">    id int primary key,</span><br><span class="line">    name varchar(20),</span><br><span class="line">    gender char(1)</span><br><span class="line">);</span><br></pre></td></tr></table></figure>
</li>
<li><p>多字段主键</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">creat table employee(</span><br><span class="line">    name_id int,</span><br><span class="line">    card_id int,</span><br><span class="line">    name varchar(20),</span><br><span class="line">    gender char(1),</span><br><span class="line">    primary key(name_id,card_id)</span><br><span class="line">);</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h4 id="非空约束"><a href="#非空约束" class="headerlink" title="非空约束"></a>非空约束</h4><p><code>NOT NULL</code>将该字段添加至数据类型后即可起到限制作用。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">creat table employee(</span><br><span class="line">    id int primary key,</span><br><span class="line">    name varchar(20),</span><br><span class="line">    gender char(1) not null</span><br><span class="line">);</span><br></pre></td></tr></table></figure>

<h4 id="唯一约束"><a href="#唯一约束" class="headerlink" title="唯一约束"></a>唯一约束</h4><p><code>UNIQUE</code>在数据类型声明之后添加该字段即可起到限制作用。主键约束也就是非空加唯一。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">creat table employee(</span><br><span class="line">    id int primary key,</span><br><span class="line">    name varchar(20) unique,</span><br><span class="line">    gender char(1) not null</span><br><span class="line">);</span><br></pre></td></tr></table></figure>

<h4 id="默认约束"><a href="#默认约束" class="headerlink" title="默认约束"></a>默认约束</h4><p><code>DEFAULT</code>给则用给的，不给则用默认的。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">creat tabel employee(</span><br><span class="line">id int primary key,</span><br><span class="line">name varchar(20) unique,</span><br><span class="line">gender char(1) not null,</span><br><span class="line">段位 varchar(50) default &#39;黑铁&#39;</span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<h4 id="自增字段"><a href="#自增字段" class="headerlink" title="自增字段"></a>自增字段</h4><p><code>AUTO_INCREMENT</code>使用该关键字可设字段自动增长</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">creat table employee(</span><br><span class="line">id int primary key auto_incremnent,</span><br><span class="line">name varchar(20) unique,</span><br><span class="line">gender char(1) not null,</span><br><span class="line">段位 varchar(50) default &#39;黑铁&#39;</span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<h3 id="索引"><a href="#索引" class="headerlink" title="索引"></a>索引</h3><h4 id="概念"><a href="#概念" class="headerlink" title="概念"></a>概念</h4><p>好比字典音序表、笔画表。是对数据表中一列或多列的值进行排序后的一种结构，作用就是提速。索引也会占内存，维护难度随着数据量增加而增加。</p>
<ul>
<li><h6 id="普通索引"><a href="#普通索引" class="headerlink" title="普通索引"></a>普通索引</h6></li>
</ul>
<p>由<code>KEY</code>或<code>INDEX</code>定义的索引（按照列或者列的编号），是否唯一和非空没固定要求</p>
<ul>
<li><h6 id="唯一索引"><a href="#唯一索引" class="headerlink" title="唯一索引"></a>唯一索引</h6></li>
</ul>
<p>使用UNIQUE定义的索引，所使用的字段必须唯一</p>
<ul>
<li><h6 id="全文索引"><a href="#全文索引" class="headerlink" title="全文索引"></a>全文索引</h6></li>
</ul>
<p>由<code>FULLTEXT</code>定义的索引，只能创建在char或varchar或text类型的字段上，而且只有MyISAM存储引擎支持。</p>
<ul>
<li><h6 id="单列索引"><a href="#单列索引" class="headerlink" title="单列索引"></a>单列索引</h6></li>
</ul>
<p>保证该索引只对应一个字段</p>
<ul>
<li><h6 id="多列索引"><a href="#多列索引" class="headerlink" title="多列索引"></a>多列索引</h6></li>
</ul>
<p>在表中多个字段上创建索引，只有在查询条件中使用了这些字段中的第一个字段时，该索引才会被使用。</p>
<h4 id="创建索引"><a href="#创建索引" class="headerlink" title="创建索引"></a>创建索引</h4><h5 id="创建表时创建索引"><a href="#创建表时创建索引" class="headerlink" title="创建表时创建索引"></a>创建表时创建索引</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">create table 表名(</span><br><span class="line">    字段名 数据类型[完整性的约束条件],</span><br><span class="line">    ...</span><br><span class="line">    字段名 数据类型[完整性的约束条件],</span><br><span class="line">    [UNIQUE|FULLTEXT|SPATILA] INDEX|KEY [别名] (字段名[(所取字端长度)]) [ASC|DESC]</span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<p><code>INDEX</code>前面可以选一个索引类型，而且<code>INDEX</code>和<code>KEY</code>，可以起个别名，然后再选建立在哪些字段上，然后是长度和升降序。</p>
<ul>
<li>普通索引</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">#关键字一个都不写就是普通索引</span><br><span class="line">creat table t1(</span><br><span class="line">    id int,</span><br><span class="line">    name carchar(20),</span><br><span class="line">    score float,</span><br><span class="line">    index (id)</span><br><span class="line">)</span><br><span class="line">#show creat table t1可以看到key id id</span><br><span class="line">#查询的时候会走索引，提高素的</span><br><span class="line">#使用explain select * from t1 where id&#x3D;1</span><br><span class="line">#可以查看它是如何完成查询的</span><br></pre></td></tr></table></figure>

<ul>
<li>唯一索引</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">creat table t2(</span><br><span class="line">    id int not null,</span><br><span class="line">    name carchar(20) not null,</span><br><span class="line">    score float,</span><br><span class="line">    unique index unique123_id123(id AES)</span><br><span class="line">    #这样就创建了一个位移性索引</span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<ul>
<li>全文索引</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">creat table t3(</span><br><span class="line">    id int not null,</span><br><span class="line">    name carchar(20) not null,</span><br><span class="line">    score float,</span><br><span class="line">    fulltext index fulltext_123_name(name)</span><br><span class="line">)engine&#x3D;MyISAM</span><br></pre></td></tr></table></figure>

<h5 id="使用CREATE语句创建索引"><a href="#使用CREATE语句创建索引" class="headerlink" title="使用CREATE语句创建索引"></a>使用CREATE语句创建索引</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">CREATE [UNIQUE|FULLTEXT] INDEX 索引名</span><br><span class="line">ON 表名(列名[(长度)] [ASC|DESC],...)</span><br></pre></td></tr></table></figure>

<ul>
<li><p>索引名：索引的名称，索引名在一个表中名称必须是唯一的。</p>
</li>
<li><p>长度：表示使用列的前多少个字符创建索引。使用列的一部分创建索引可以使索引文件大大减小，从而节省磁盘空间。<strong>BLOB</strong>或<strong>TEXT</strong>列必须用前缀索引。</p>
</li>
<li><p><strong>CREATE INDEX</strong> 语句并不能创建主键。</p>
</li>
</ul>
<h5 id="使用ALTER-TABLE语句创建索引"><a href="#使用ALTER-TABLE语句创建索引" class="headerlink" title="使用ALTER TABLE语句创建索引"></a>使用ALTER TABLE语句创建索引</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">ALTER TABLE 表名</span><br><span class="line">	ADD INDEX [索引名] (列名,...) #添加索引</span><br><span class="line">	|ADD PRIMARY KEY [索引方式] (列名,...) #添加主键！！</span><br><span class="line">	|ADD UNIQUE [索引名] (列名,...) #添加唯一性索引</span><br><span class="line">	|ADD FULLTEXT [索引名] (列名,...) #添加全文索引</span><br></pre></td></tr></table></figure>

<h4 id="删除索引"><a href="#删除索引" class="headerlink" title="删除索引"></a>删除索引</h4><ol>
<li><p>使用<code>DROP INDEX</code>语句删除</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">DROP INDEX 索引名 ON 表名</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用<code>ALTER TABLE</code>语句删除</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ALTER TABLE 表名</span><br><span class="line">	DROP PRIMARY KEY #删除主键</span><br><span class="line">	DROP INDEX 索引名 #删除索引</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h2 id="第三章-添加、更新与删除数据"><a href="#第三章-添加、更新与删除数据" class="headerlink" title="第三章 添加、更新与删除数据"></a>第三章 添加、更新与删除数据</h2><h3 id="添加数据"><a href="#添加数据" class="headerlink" title="添加数据"></a>添加数据</h3><p>自增字段给<code>NULL</code>值，即可实现自增效果。</p>
<p>插入多条记录，添加逗号即可。</p>
<ul>
<li><p>不指定列名插入，按顺序填充整表所有列</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">INSERT INTO 表名 VALUES (列1value，列2value...)</span><br></pre></td></tr></table></figure>
</li>
<li><p>指定列名插入</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">INSERT INTO 表名 (列1,列2...) VALUES (列1value，列2value...) #对应填充</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h3 id="更新数据"><a href="#更新数据" class="headerlink" title="更新数据"></a>更新数据</h3><ul>
<li>修改所有列值</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">UPDATE 表名 SET 列名&#x3D;值 #这样会修改表中这一列的所有值</span><br></pre></td></tr></table></figure>

<ul>
<li>修改指定列值</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">UPDATE 表名 SET 列名&#x3D;值</span><br><span class="line">WHERE 列名2&#x3D;列值</span><br><span class="line">#这样会修改指定列值</span><br><span class="line">update 员工表 set 薪水&#x3D;2500 where 姓名&#x3D;&#39;张三&#39;</span><br></pre></td></tr></table></figure>

<ul>
<li>同时指定修改多列的值</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">UPDATE 表名 SET 列名1&#x3D;值1,列名2&#x3D;值2...</span><br><span class="line">WHERE 列名3&#x3D;列值</span><br><span class="line">#这样可以同时修改多列的值</span><br></pre></td></tr></table></figure>

<ul>
<li>指定列运算修改</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">UPDATE 员工表 SET 薪水&#x3D;薪水+1000 WHERE 姓名&#x3D;&#39;刘备&#39;;</span><br></pre></td></tr></table></figure>

<h3 id="删除数据"><a href="#删除数据" class="headerlink" title="删除数据"></a>删除数据</h3><p>区别使用<code>DROP 表名</code>来删除表，而这是删除记录。</p>
<ul>
<li>使用<code>DELETE</code>删除</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">DELETE FROM 表名 [WHERE where子句] #表面意思</span><br></pre></td></tr></table></figure>

<ul>
<li><p>使用<code>TRUNCATE</code>删除表</p>
<p>它会摧毁原表，再建一个结构一摸一样的空表，缺点不能单独删除某一条。</p>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">TRUNCATE 表名</span><br></pre></td></tr></table></figure>

<h2 id="第四章-表单查询"><a href="#第四章-表单查询" class="headerlink" title="第四章 表单查询"></a>第四章 表单查询</h2><h3 id="简单查询"><a href="#简单查询" class="headerlink" title="简单查询"></a>简单查询</h3><h4 id="全部查询"><a href="#全部查询" class="headerlink" title="全部查询"></a>全部查询</h4><p><code>DISTINCT</code>去除重复值，写在<code>SELECT</code>后面就行。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">SELECT DISTINCT *|列名1[,列名2...]</span><br><span class="line">FROM 表名</span><br></pre></td></tr></table></figure>

<h4 id="查询并运算后显示"><a href="#查询并运算后显示" class="headerlink" title="查询并运算后显示"></a>查询并运算后显示</h4><p>下边是个成绩加十分的查询。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SELECT name,math+10,english+10 from 表名</span><br></pre></td></tr></table></figure>

<h4 id="指定别名"><a href="#指定别名" class="headerlink" title="指定别名"></a>指定别名</h4><p>下面是个总成绩的查询，先简单使用<code>表达式</code>和<code>AS</code>别名。这个<code>AS</code>还可以用空格代替？！学到了</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SELECT ENG+MATH+CHINESE AS 总成绩 FROM 表名</span><br></pre></td></tr></table></figure>

<h3 id="条件查询"><a href="#条件查询" class="headerlink" title="条件查询"></a>条件查询</h3><h4 id="WHERE子句过滤查询"><a href="#WHERE子句过滤查询" class="headerlink" title="WHERE子句过滤查询"></a><code>WHERE</code>子句过滤查询</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SELECT * FROM 表名 WHERE 姓名&#x3D;&#39;张飞&#39;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from 表名 where math+English+Chinese&gt;200</span><br></pre></td></tr></table></figure>

<p>经常使用的运算符有：</p>
<p>逻辑运算符：<code>and</code> <code>or</code> <code>not</code></p>
<p>比较运算符：<code>&gt;，&lt;，&gt;=，&lt;=，=，&lt;&gt;</code> 最后一个是不等于</p>
<p>还有<code>in</code> <code>not in</code> <code>like</code> <code>is null</code> 字面意思理解</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select 姓名 from 表名 where 英语 between 80 and 90</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from 表名 where math in (70,80,90)</span><br></pre></td></tr></table></figure>

<p>查找一个，名字中第二个字是<code>天</code>的同学，我叫<code>文天爸</code>。。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from 表名 where 姓名 like &#39;_天%&#39;</span><br></pre></td></tr></table></figure>

<p>多个条件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from 表名 where 语文&gt;70 and math&gt;80</span><br></pre></td></tr></table></figure>

<h4 id="聚合函数"><a href="#聚合函数" class="headerlink" title="聚合函数"></a>聚合函数</h4><ol>
<li>COUNT()，统计行数</li>
<li>SUM()，求某列的和值</li>
<li>AVG()，平均分</li>
<li>MAX()，最大值</li>
<li>MIN()，最小值</li>
</ol>
<h4 id="带有排序的查询"><a href="#带有排序的查询" class="headerlink" title="带有排序的查询"></a>带有排序的查询</h4><p>关键字<code>ORDER BY</code></p>
<p><code>select name,math from 表名 order by 前面出现过的列名或者as后的列名 asc|desc</code>，升序|降序。</p>
<p>后期会列出子句顺序，这个排序应位于<code>select</code>语句<code>where</code>后面。</p>
<h4 id="分组查询"><a href="#分组查询" class="headerlink" title="分组查询"></a>分组查询</h4><p>可以按照某一列或者几列进行分组。</p>
<p>多列要全部符合才会归为一组。</p>
<p><code>having</code>子句，而且<code>select</code>语句中可以使用聚合函数（此时聚合函数作用域为<code>分组后并且选取的组区域</code>。）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SELECT 男,count(*) as 总人数 FROM 表名 GROUP BY 性别</span><br></pre></td></tr></table></figure>

<p><code>where</code>子句中不可使用聚合函数。</p>
<h4 id="使用LIMIT限制查询结果的数量"><a href="#使用LIMIT限制查询结果的数量" class="headerlink" title="使用LIMIT限制查询结果的数量"></a>使用LIMIT限制查询结果的数量</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SELECT 字段1，字段2... FROM 表名 LIMIT [开始的位置,] 记录条数</span><br></pre></td></tr></table></figure>

<p>与<code>group by</code>、<code>order by</code>同级，建议写到最后。</p>
<p>须注意的是开始位置从<code>0</code>开始计算。</p>
<h4 id="常用函数"><a href="#常用函数" class="headerlink" title="常用函数"></a>常用函数</h4><h5 id="函了个数，方了个法。"><a href="#函了个数，方了个法。" class="headerlink" title="函了个数，方了个法。"></a>函了个数，方了个法。</h5><p><strong>SQL聚集函数</strong><br>AVG() ————返回某列的平均值<br>COUNT() ——–返回某列的行数<br>MAX() ————返回某列的最大值<br>MIN() ————-返回某列的最小值<br>SUM() ————返回某列值之和</p>
<p><strong>常用的文本处理函数</strong><br>Left() —————返回串左边的字符<br>Length()———– 返回串的长度<br>Locate()———– 找出串的一个子串<br>Lower() ———–将串转换为小写<br>LTrim() ————去掉串左边的空格<br>Right()———— 返回串右边的字符<br>RTrim()———- -去掉串右边的空格<br>Soundex() ——-返回串的SOUNDEX值<br>SubString()—— 返回子串的字符<br>Upper()———– 将串转换为大写</p>
<p><strong>常用日期和时间处理函数</strong></p>
<p>AddDate() ———-增加一个日期（天、周等）<br>AddTime()———- 增加一个时间（时、分等）<br>CurDate() ———–返回当前日期<br>CurTime()————返回当前时间<br>Date() —————-返回日期时间的日期部分<br>DateDiff()———– -计算两个日期之差<br>Date_Add()———-高度灵活的日期运算函数<br>Date_Format() —–返回一个格式化的日期或时间串<br>Day() —————–返回一个日期的天数部分<br>DayOfWeek()——-对于一个日期，返回对应的星期几<br>Hour() —————返回一个时间的小时部分<br>Minute()———– -返回一个时间的分钟部分<br>Month() ————返回一个日期的月份部分<br>Now()————- -返回当前日期和时间<br>Second()———- 返回一个时间的秒部分<br>Time()———— -返回一个日期时间的时间部分<br>Year()————– 返回一个日期的年份部分</p>
<p><strong>常用数值处理函数</strong></p>
<p>Abs() —————返回一个数的绝对值<br>Cos()————— 返回一个角度的余弦<br>Exp()————— 返回一个数的指数值<br>Mod() ————–返回除操作的余数<br>Pi() ——————返回圆周率<br>Rand() ————-返回一个随机数<br>Sin() —————-返回一个角度的正弦<br>Sqrt() —————返回一个数的平方根<br>Tan() —————-返回一个角度的正切  </p>
<h5 id="数据类型-1"><a href="#数据类型-1" class="headerlink" title="数据类型"></a>数据类型</h5><p><strong>字符串数据类型</strong><br>CHAR —————–1～255个字符的定长串。它的长度必须在创建时指定，否则MySQL假定为CHAR(1)<br>ENUM —————-接受最多64 K个串组成的一个预定义集合的某个串<br>LONGTEXT—- —–与TEXT相同，但最大长度为4 GB<br>MEDIUMTEXT —–与TEXT相同，但最大长度为16 K<br>SET ——————-接受最多64个串组成的一个预定义集合的零个或多个串<br>TEXT—————– 最大长度为64 K的变长文本<br>TINYTEXT ———-与TEXT相同，但最大长度为255字节<br>VARCHAR———- 长度可变，最多不超过255字节。在创建时可指定为VARCHAR(n)，（其中 n≤255）</p>
<p><strong>数值数据类型</strong><br>BIT ———-位字段，1～64位。<br>BIGINT—– 支持 —9223372036854775808～9223372036854775807<br>         （如果是UNSIGNED，为0～18446744073709551615）的数<br>BOOLEAN（或BOOL）—– 布尔标志，或者为0或者为1，主要用于开/关（on/off）标志<br>DECIMAL（或DEC）—– 精度可变的浮点值<br>DOUBLE———- 双精度浮点值<br>FLOAT———– 单精度浮点值<br>INT—— ———-支持 —2147483648～2147483647（如果是UNSIGNED，为0～4294967295）的数<br>MEDIUMINT —————支持 —8388608～8388607（如果是UNSIGNED，为0～16777215）的数<br>SMALLINT ——————支持 —32768～32767（如果是UNSIGNED，为0～65535）的数<br>TINYINT——————- 支持 —128～127（如果为UNSIGNED，为0～255）的数</p>
<p><strong>日期和时间数据类型</strong><br>DATE ————-表示1000-01-01～9999-12-31的日期，格式为YYYY-MM-DD<br>DATETIME ——DATE和TIME的组合<br>TIMESTAMP— 功能和DATETIME相同（但范围较小）<br>TIME————- 格式为HH:MM:SS<br>YEAR———– 用2位数字表示，范围是70（1970年）～69（2069年），用4位数字表示，范围是1901年～2155年</p>
<p><strong>二进制数据类型</strong><br>BLOB ———————Blob最大长度为64 KB<br>MEDIUMBLOB——– Blob最大长度为16 MB<br>LONGBLOB———– Blob最大长度为4 GB<br>TINYBLOB———— Blob最大长度为255字节</p>
<h4 id="别名"><a href="#别名" class="headerlink" title="别名"></a>别名</h4><p>为了直观查看。</p>
<p>可以为<code>表</code>指定别名，为<code>字段</code>指定别名。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SELECT * FROM 表名 [AS] 别名</span><br></pre></td></tr></table></figure>

<p>为字段：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select name as 学生姓名 from 学生表;</span><br></pre></td></tr></table></figure>

<h2 id="第五章-多表操作"><a href="#第五章-多表操作" class="headerlink" title="第五章 多表操作"></a>第五章 多表操作</h2><h3 id="外键"><a href="#外键" class="headerlink" title="外键"></a>外键</h3><ol>
<li><p>创建表时添加外键</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">create table 部门表(</span><br><span class="line">	id int primary key auto_increment,</span><br><span class="line">	部门名称 varchar(40)</span><br><span class="line">);</span><br><span class="line">create table 员工表(</span><br><span class="line">	id int primary key auto_increment,</span><br><span class="line">	姓名 varchar(20),</span><br><span class="line">    部门id int,</span><br><span class="line">    foreign key (id) references 部门表(id)</span><br><span class="line">    #这一行语句就像之前学过的设置多字段主键</span><br><span class="line">    #谁是外键参照谁被动。</span><br><span class="line">);</span><br></pre></td></tr></table></figure>
</li>
<li><p>通过<code>修改表</code>添加外键</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ALTER table 表名 add constraint &#39;外键名&#39; foreign key(外键字段名) references 外表表名(主键字段名)</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除外键</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">alter table 表名 drop foreign key 外键名</span><br></pre></td></tr></table></figure>

<p>对于这个外键名，可以在创建表时添加约束<code>constraint</code>；</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">create table 员工表(</span><br><span class="line">	id int primary key auto_increment,</span><br><span class="line">	姓名 varchar(20),</span><br><span class="line">    部门id int,</span><br><span class="line">    CONSTRAINT &#39;外键名&#39; foreign key (id) references 部门表(id)</span><br><span class="line">    #这一行语句就像之前学过的设置多字段主键</span><br><span class="line">    #谁是外键参照谁被动。</span><br><span class="line">);</span><br></pre></td></tr></table></figure>



</li>
</ol>
<h3 id="为关联表添加数据"><a href="#为关联表添加数据" class="headerlink" title="为关联表添加数据"></a>为关联表添加数据</h3><p><em>references：</em></p>
<p><em>n.[图情] 参考文献, 参照, 推荐信（reference的复数）</em></p>
<p><em>v.附…以供参考, 把…引作参考（reference的三单形式）</em></p>
<p> 确定E-R关系：</p>
<ol>
<li><code>一对多</code>，那么在<code>多</code>的一方设置外键，保存<code>一</code>的一方的主键。</li>
<li><code>一对一</code>，可以在任意一方保存另外一方的主键。</li>
<li><code>多对多</code>，新建一张<code>第三方关系表</code>，保存两张表的主键作为外键，存储两张表<code>主键与主键</code>之间的对应关系，来保存两张表之间的关系。</li>
</ol>
<p>需要注意：</p>
<p>插入数据时，先插入参照列的数据，才能插入关联列的数据。</p>
<h3 id="删除关联表数据"><a href="#删除关联表数据" class="headerlink" title="删除关联表数据"></a>删除关联表数据</h3><h3 id="交叉连接"><a href="#交叉连接" class="headerlink" title="交叉连接"></a>交叉连接</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from 表1、表2。。。;</span><br></pre></td></tr></table></figure>

<p>这个叫笛卡尔积查询，左右相乘。</p>
<h4 id="内连接查询"><a href="#内连接查询" class="headerlink" title="内连接查询"></a>内连接查询</h4><p><code>左有右有</code>的记录</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from 部门表,员工表 where 部门表.id &#x3D; 员工表.部门id</span><br></pre></td></tr></table></figure>

<p>另一种写法：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from 部门表 inner join 员工表 on 部门表.id &#x3D; 员工表.部门id</span><br></pre></td></tr></table></figure>

<h4 id="左外链接查询"><a href="#左外链接查询" class="headerlink" title="左外链接查询"></a>左外链接查询</h4><p><code>在内连接的基础上</code>，增加上<code>左有右无</code>的记录</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from 部门表 left join 员工表 on 部门表.id &#x3D; 员工表.部门id</span><br></pre></td></tr></table></figure>

<h4 id="右外链接查询"><a href="#右外链接查询" class="headerlink" title="右外链接查询"></a>右外链接查询</h4><p><code>在内连接的基础上</code>，增加上<code>左无右有</code>的记录</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from 部门表 right join 员工表 on 部门表.id &#x3D; 员工表.部门id</span><br></pre></td></tr></table></figure>

<h4 id="全外链接查询"><a href="#全外链接查询" class="headerlink" title="全外链接查询"></a>全外链接查询</h4><p><code>在内连接的基础上</code>，增加上<code>左有右无</code>和<code>左无右有</code>的记录</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from 部门表 full join 员工表 on 部门表.id &#x3D; 员工表.部门id</span><br></pre></td></tr></table></figure>

<p>如果不支持全外链接查询的话，可以使用<code>union</code>连接左右外两个连接:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">select * from 部门表 left join 员工表 on 部门表.id &#x3D; 员工表.部门id</span><br><span class="line">union</span><br><span class="line">select * from 部门表 right join 员工表 on 部门表.id &#x3D; 员工表.部门id</span><br></pre></td></tr></table></figure>

<h3 id="带有IN关键字的子查询"><a href="#带有IN关键字的子查询" class="headerlink" title="带有IN关键字的子查询"></a>带有IN关键字的子查询</h3><p>使用嵌套的思想来理解。但是内层查询需要返回<code>单列数据</code>。</p>
<p>外边这个查询可以使用里边这个查询作为范围来进行二次查询。</p>
<p>查询四班身高大于1.8米的女同学的名字</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select 姓名 from 四班 where 姓名 in (select 姓名 from 学生表 where 身高&gt;180 and 性别&#x3D;&#39;女&#39; )</span><br></pre></td></tr></table></figure>

<h3 id="带有EXISTS关键字的查询"><a href="#带有EXISTS关键字的查询" class="headerlink" title="带有EXISTS关键字的查询"></a>带有EXISTS关键字的查询</h3><p>如果内层查询的值存在，才会继续查询。返回TRUE和FALSE两个值</p>
<p>查询员工表中是否存在年龄大于23岁的员工，如果是，则返回所存在的部门记录。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from 部门表 where exists (select * form 员工表 where 年龄 &gt; 23)</span><br></pre></td></tr></table></figure>

<h4 id="带有ANY关键字的查询"><a href="#带有ANY关键字的查询" class="headerlink" title="带有ANY关键字的查询"></a>带有ANY关键字的查询</h4><p>ANY表示满足其中任意一个条件，允许创建表达式对子查询的返回值列表进行比较。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from 部门表 where id &gt;any(select 部门id from 员工表)</span><br></pre></td></tr></table></figure>

<h4 id="带有ALL关键字的查询"><a href="#带有ALL关键字的查询" class="headerlink" title="带有ALL关键字的查询"></a>带有ALL关键字的查询</h4><p>ALL表示满足所有条件，允许创建表达式对子查询的返回值列表进行比较。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from 部门表 where id &gt;all(select 部门id from 员工表)</span><br></pre></td></tr></table></figure>

<h4 id="带比较运算符的查询"><a href="#带比较运算符的查询" class="headerlink" title="带比较运算符的查询"></a>带比较运算符的查询</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select 部门名称 from 部门表 where id &#x3D; (select id from 员工表 where 姓名&#x3D;&#39;赵四&#39;)</span><br></pre></td></tr></table></figure>

<h2 id="第六章-事务和存储过程"><a href="#第六章-事务和存储过程" class="headerlink" title="第六章 事务和存储过程"></a>第六章 事务和存储过程</h2><h3 id="事务"><a href="#事务" class="headerlink" title="事务"></a>事务</h3><ol>
<li>创建事务：<code>start transaction</code>开启事务，后续语句在同一事务之中，不会立即影响到数据库。</li>
<li>…SQL语句…</li>
<li>[回滚事务：<code>rollback</code>]，放弃这个事务，当前事务不会对数据库产生影响。</li>
<li><code>commit</code>提交事务；</li>
</ol>
<p>ACID性质</p>
<h3 id="事务的隔离级别"><a href="#事务的隔离级别" class="headerlink" title="事务的隔离级别"></a>事务的隔离级别</h3><p>多线程并发安全性。</p>
<ol>
<li><p>两个并发的修改，必须隔离开。</p>
</li>
<li><p>两个并发的查询，完全不隔离。</p>
</li>
<li><p>一个查询，一个修改，存在以下特殊情况：</p>
<ul>
<li><p>脏读，一个事务读取到了另一个事务未提交的数据。</p>
<p>从事务的角度取去理解，就像转账：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">假设账户表：</span><br><span class="line">----  -----</span><br><span class="line">user  money</span><br><span class="line">----  -----</span><br><span class="line">guset 1000</span><br><span class="line">admin 1000</span><br><span class="line">----  -----</span><br><span class="line"></span><br><span class="line">guest:</span><br><span class="line">	start transaction;</span><br><span class="line">	update account set money&#x3D;money-100 where name&#x3D;&#39;guset&#39;; #guest转出100元</span><br><span class="line">	update account set money&#x3D;money+100 where name&#x3D;&#39;admin&#39;; #管理员收到100元</span><br><span class="line">	# 关键点出现了，游客没进行提交</span><br><span class="line">	admin:</span><br><span class="line">		start transaction;</span><br><span class="line">		select * form account;</span><br><span class="line">            ----  -----</span><br><span class="line">            user  money</span><br><span class="line">            ----  -----</span><br><span class="line">            guset 900</span><br><span class="line">            admin 1100</span><br><span class="line">            ----  -----</span><br><span class="line">		#至此管理员以为收到了100元</span><br><span class="line">		commit;</span><br><span class="line">		#处理了游客的请求</span><br><span class="line">guest:</span><br><span class="line">	#鸡贼的地方出来了</span><br><span class="line">	rollback;</span><br><span class="line">	那么这样的话，游客白嫖了一次服务。</span><br></pre></td></tr></table></figure>
</li>
<li><p>不可重复读：一个事物多次读取同一条记录，读取的结果不相同(本质：一个事务读取到另一个事务已经提交的数据)</p>
</li>
<li><p>虚读(幻读)：一个事务多次查询整表的数据，由于其他事务删除(新增)记录造成多次查询出的记录条数不同(本质：一个事务读取到另一个事务已经提交的数据)</p>
</li>
</ul>
</li>
</ol>
<p>为了解决以上问题，研究出了四大隔离界别：</p>
<ol>
<li><code>read uncommitted</code> 不做任何隔离</li>
<li><code>read committed</code> 可防止脏读，不可防止重复读、虚读(幻读)</li>
<li><code>repeatable</code> 可防止脏读，不可防止重复读、虚读(幻读)</li>
<li><code>serializable</code> 数据库运行在串行模式下，所有问题都没有，但是性能非常低。</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">set [session&#x2F;global] transaction isolatiion level 以上四选一; #修改隔离级别</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select @@tx_isolation #查询当前隔离级别</span><br></pre></td></tr></table></figure>


        </div>

        <blockquote class="post-copyright">
    
    <div class="content">
        
<span class="post-time">
    Last updated: <time datetime="2021-01-13T08:23:28.193Z" itemprop="dateUpdated">2021-01-13 16:23:28</time>
</span><br>


        
        这里可以写作者留言，标签和 hexo 中所有变量及辅助函数等均可调用，示例：<a href="/blog/2020/12/18/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/" target="_blank" rel="external">https://gitee.com/songbug/blog.git/2020/12/18/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/</a>
        
    </div>
    
    <footer>
        <a href="https://gitee.com/songbug/blog.git">
            <img src="/blog/img/avatar.jpg" alt="Song Wani">
            Song Wani
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            

            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://gitee.com/songbug/blog.git/2020/12/18/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/&title=《MySQL数据库》 — SongKaBaKa&pic=https://gitee.com/songbug/blog.git/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://gitee.com/songbug/blog.git/2020/12/18/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/&title=《MySQL数据库》 — SongKaBaKa&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://gitee.com/songbug/blog.git/2020/12/18/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《MySQL数据库》 — SongKaBaKa&url=https://gitee.com/songbug/blog.git/2020/12/18/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/&via=https://gitee.com/songbug/blog.git" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://gitee.com/songbug/blog.git/2020/12/18/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/blog/2021/01/13/0.02%E5%B9%B4%E5%AD%A6%E4%BC%9Alinux/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">0.02年学会linux</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/blog/2020/11/17/JavaScript%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">JavaScript学习笔记</h4>
      </a>
    </div>
  
</nav>



    




















</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        谢谢大爷~
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content">
        
        <div class="reward-code">
            <img id="rewardCode" src="/blog/img/wechat.jpg" alt="打赏二维码">
        </div>
        
        <label class="reward-toggle">
            <input id="rewardToggle" type="checkbox" class="reward-toggle-check"
                data-wechat="/blog/img/wechat.jpg" data-alipay="/blog/img/alipay.jpg">
            <div class="reward-toggle-ctrol">
                <span class="reward-toggle-item wechat">微信</span>
                <span class="reward-toggle-label"></span>
                <span class="reward-toggle-item alipay">支付宝</span>
            </div>
        </label>
        
    </div>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
            <span>This blog is licensed under a <a rel="license noopener" href="https://creativecommons.org/licenses/by/4.0/" target="_blank">Creative Commons Attribution 4.0 International License</a>.</span>
        </p>
    </div>
    <div class="bottom">
        <p><span>Song Wani &copy; 2019 - 2021</span>
            <span>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://gitee.com/songbug/blog.git/2020/12/18/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/&title=《MySQL数据库》 — SongKaBaKa&pic=https://gitee.com/songbug/blog.git/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://gitee.com/songbug/blog.git/2020/12/18/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/&title=《MySQL数据库》 — SongKaBaKa&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://gitee.com/songbug/blog.git/2020/12/18/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《MySQL数据库》 — SongKaBaKa&url=https://gitee.com/songbug/blog.git/2020/12/18/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/&via=https://gitee.com/songbug/blog.git" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://gitee.com/songbug/blog.git/2020/12/18/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="//api.qrserver.com/v1/create-qr-code/?data=https://gitee.com/songbug/blog.git/2020/12/18/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/blog/', SHARE: true, REWARD: true };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>






<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = '死鬼去哪里了！';
            clearTimeout(titleTime);
        } else {
            document.title = '(つェ⊂)咦!又好了!';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
